<?php namespace App\Core\Repository\Sorts;

use App\Core\Repository\Sort;

class ManualDragSort extends Sort {
    
    public function __construct($config){
        parent::__construct($config);
    }
    
    //执行排序
    public function sort($operation, $selfId, $targetId = ''){
		if(empty($selfId) || !in_array($operation, ['append', 'prepend', 'cancel', 'before', 'after'])){
			throw new \Exception('parameter not validated');
		}
        if(in_array($operation, ['before', 'after']) && empty($targetId)){
            throw new \Exception('parameter not validated');
        }
        if($operation == 'append'){
            $this->append($selfId);
        }elseif($operation == 'prepend'){
            $this->prepend($selfId);
        }elseif($operation == 'cancel'){
            $this->cancel($selfId);
        }elseif($operation == 'before'){
            $this->before($selfId, $targetId);
        }elseif($operation == 'after'){
            $this->after($selfId, $targetId);
        }
    }
}